﻿@model _PLATFORM.DATA.PRODUCT

@{
    ViewBag.Title = "Create";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div id="subNav">
    <ul>
    	<li>@Html.ActionLink("Systems Management", "IndexList", "TruckingSystem")</li>
        @if(ViewBag.ProductType == "Component"){
            <li class="select">@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
            <li>@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>            
        }
        else{
            <li>@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
            <li class="select">@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>
        }
    </ul>
</div>

@if (ViewBag.ProductType == "Component")
{
    <br /><h2>Component Management</h2>
}
else { 
    <br /><h2>Spare Part Management</h2>
}

<div id="subNav2">
    @if (ViewBag.ProductType == "Component")
    {
        <ul>
    	    <li>@Html.ActionLink("Current Components", "Index", "Component", new { productType = "Component" }, null)</li>
            <li  class="select">@Html.ActionLink("Create New Component", "Create", "Component", new { productType = "Component" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
            <li>@Html.ActionLink("Manage Component Selections", "Index", "SelectionOption", new { productType = "Component" }, null)</li>
        </ul>
    }
    else
    {
        <ul>
    	    <li>@Html.ActionLink("Current Spare Parts", "Index", "Component", new { productType = "SparePart" }, null)</li>
            <li  class="select">@Html.ActionLink("Create New Spare Parts", "Create", "Component", new { productType = "SparePart" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
            <li>@Html.ActionLink("Manage Spare Parts Selections", "Index", "SelectionOption", new { productType = "SparePart" }, null)</li>
        </ul>
    }
</div>

@using (Html.BeginForm("Create", "Component", FormMethod.Post, new { enctype="multipart/form-data" }))
{
    @Html.ValidationSummary(true)
    
    <div id="lowerContainer">
		<div id="lowerContainerInner">
	        @using (Html.BeginForm("Create", "Component", FormMethod.Post, new { enctype = "multipart/form-data" })) {
		        @Html.ValidationSummary(true) 
		        <fieldset>
		            <table id="tableMgmt" style="width: 100%;">
		                <tr>
			                
                            @if (ViewBag.ProductType == "Component")
                            {
                                <td class="td160"><b>Component Name</b></td>
                            }
                            else { 
                                <td class="td160"><b>Spare Part Name</b></td>
                            }
			                <td>@Html.TextBoxFor(model => model.NAME) @Html.ValidationMessageFor(model => model.NAME) </td>
		                </tr>
		                <tr>
			                <td><b>Image</b></td>
			                <td>
				                <input type="file" id="file1" name="file1" value="Upload" style="width: 126px;" accept="image/jpeg, image/png, image/gif" />
			                </td>
		                </tr>
		                <tr>
			                <td><b>Cost</b></td>
			                <td>@Html.TextBoxFor(model => model.COST) @Html.ValidationMessageFor(model => model.COST) </td>
		                </tr>
		                <tr>
			                <td><b>Price</b></td>
			                <td>@Html.TextBoxFor(model => model.PRICE) @Html.ValidationMessageFor(model => model.PRICE) </td>
		                </tr>
		                <tr>
			                <td><b>Part Number</b></td>
			                <td>@Html.TextBoxFor(model => model.PART_NUMBER) @Html.ValidationMessageFor(model => model.PART_NUMBER) </td>
		                </tr>
		                <tr>
			                <td><b>Supplier</b></td>
			                <td>
				                @{
                                    var supplierList = ViewBag.SupplierSelectList as SelectList;
                                    @Html.DropDownList("Supplier", supplierList) 
                                }
				
				                <a href="#" id="A5" class="example6 button default btnSmall">Add +</a>
			                </td>
		                </tr>
		                <tr>
			                <td>
				                <b>Lead Time</b>
			                </td>
			                <td>
				                @Html.TextBoxFor(model => model.LEAD_TIME, new { style = "width: 147px;" })@Html.ValidationMessageFor(model => model.LEAD_TIME) 
				                @Html.DropDownList("leadTypes", ViewBag.LeadTypes as SelectList, new {style = "width:50px;"}) 
			                </td>
		                </tr>
		                <tr>
			                <td><b>Inventory</b></td>
			                <td>@Html.TextBoxFor(model => model.INVENTORY) @Html.ValidationMessageFor(model => model.INVENTORY) </td>
		                </tr>
                    
                            @{
                                if (ViewBag.ProductType == "Component") 
                                {
                                    var fittingTypeAssets = ViewBag.FittingTypeAssetList as IEnumerable<_PLATFORM.DATA.FITTING_TYPE_ASSET>;
                                    var productFittingTypeAssets = ViewBag.ProductFittingTypeAssets as IEnumerable<_PLATFORM.DATA.PRODUCT_FITTING_TYPE_ASSET>;

                                    foreach (var fittingType in ViewBag.FittingTypes as List<_PLATFORM.DATA.FITTING_TYPE>)
                                    {
                                        <tr>
                                            <td>
                                                <b>@Html.Label(fittingType.NAME)</b>
                                            </td>
                                            @{
                                                var mainList = fittingTypeAssets.Where(f => f.FITTING_TYPE_ID == fittingType.FITTING_TYPE_ID).OrderBy(t => t.NAME);
                                                var subList = productFittingTypeAssets.Where(p => p.PRODUCT_ID == ViewBag.ProductID).Where(p => p.FITTING_TYPE_ASSET.FITTING_TYPE_ID == fittingType.FITTING_TYPE_ID).Select(s => s.FITTING_TYPE_ASSET.FITTING_TYPE_ASSET_ID).ToList();
                                                var finalList = new MultiSelectList(mainList, "FITTING_TYPE_ASSET_ID", "NAME");
                                
                                            }
                                            <td>
                                                @{
                                                    var categoryName = fittingType.NAME;    
                                                }
                                                @Html.ListBox(categoryName, finalList)
                                            </td>
                                        </tr>
                                    }
                                }
                            }
                               
		                <tr>
			                <td><b>Statistical Numbers</b></td>
			                <td>@Html.TextAreaFor(model => model.STATISTICS) @Html.ValidationMessageFor(model => model.STATISTICS) </td>
		                </tr>
		                <tr>
			                <td><b>Description</b></td>
			                <td>@Html.TextAreaFor(model => model.DESCRIPTION) @Html.ValidationMessageFor(model => model.DESCRIPTION) </td>
		                </tr>
		                <tr>
			                <td><b>Upload PDF File</b></td>
			                <td><input type="file" id="descripPDF" name="files" value="Upload PDF" style="width: 126px;" accept="application/pdf" /></td>
		                </tr>
		                <tr>
			                <td></td>
			                <td><input type="submit" value="Save" class="button default btnLarge" /><a href="../../Component?productType=Component" class="button cancel btnLarge">Cancel</a></td>
		                </tr>
	                </table>
	            </fieldset>
         } 

		</div>
	</div>
}

